// functions -------------------------------------------------------------------
function nowdate(){
  $("span#hktime").html("北京时间：<b>"+now.getDate()+ "日" +(now.getHours())+":"+(now.getMinutes())+":"+(now.getSeconds()+"</b>"));
  now.setTime(now.getTime() + 1000);
  setTimeout("nowdate()",1000);
}

var reflashTime = true;
function countdown(){
    if (timestap >= 0) {
      timediff = timestap;
      days = Math.floor(timediff / (60 * 60 * 24)); 
    	timediff -= days * (60 * 60 * 24);
    	hours = Math.floor(timediff / (60 * 60));
    	timediff -= hours * (60 * 60);
    	mins = Math.floor(timediff / (60));
    	timediff -= mins * (60);
    	secs = Math.floor(timediff);
        
      str = " || 距离截止下注时间还有 ";
      if (days > 0 ) str += "<b>" + days + "</b> 天 ";
      if (hours > 0) str += "<b>" + hours + "</b> 小时 ";
      if (mins > 0) str += "<b>" + mins + "</b> 分钟 ";
      str += "<b>" + secs + "</b> 秒 ";
      $("span#countdownstr").html(str);
      setTimeout("countdown()",1000)
      if($("select#reflashtime").val() != 0){$(this).chgMinData();} // reflash time
      timestap-=1;
      if (timestap==0) {
          $("input#btnReflash").click();
	    }
    } else {
		window.setInterval(function(e){
				document.location.href=document.location.href.replace(/id=(\d)/g,"");
			},30000);
        $("span#countdownstr").html("<font color=red><b>已经截止下注 !</b></font>");
    }
}

function myNowPageReload(){
  window.location.reload();
}

// jQuery Functions ------------------------------------------------------------
$.fn.getAjaxDataAuto = function(playtype, _lotto_id){  
  // window.open('op.php?op=agent&fp=xmlBetTotal_sb&' + $("form#frmMenu").serialize());
 // return;  
 $.getJSON('op.php?op=agent&fp=xmlBetTotal_sb&' + $("form#frmMenu").serialize() ,function(ratedata){
      var dataLen = 0;
      var urlPre = "";
      var hrefStr = "";
      
      if(ratedata.errormsg != undefined){
        $("div#errormsg").addClass("error").text("No Rate data");
      }else{
          switch(playtype){
              case 'r1': show_r1(_lotto_id, playtype, ratedata, _myHeader); break;
              case 'r2': show_r2(_lotto_id, playtype, ratedata, _myHeader); break;
			  case 'r3': show_r3(_lotto_id, playtype, ratedata, _myHeader); break;
			  case 'r4': show_r4(_lotto_id, playtype, ratedata, _myHeader); break;
			  case 'r5': show_r5(_lotto_id, playtype, ratedata, _myHeader); break;
              default: show_default(); break; 
          }
          
          // set url
          $("span.span3da").click(function(){ $(this).setSpanAUrl(); });
          
          // show the menu bar for amount of each page
          $().showPgTotalAmount(ratedata.pgTotalAmountStr);

          // can change again
          $("form#frmMenu input").add("form#frmMenu select").removeAttr("disabled");
          
          // change tr color
          //$().chgTrColor();
      }
  });
};

$.fn.chgMinData = function(){
  tempMin = parseInt($("span#reflashtimeMin").text());
  if(tempMin == 0){
    //$(this).getAjaxDataAuto();
    $("input#btnReflash").click();
    $("span#reflashtimeMin").text(myGlobalVal.reloadCK);
  }else if(!$("select#reflashtime").attr("disabled")){
    $("span#reflashtimeMin").text(tempMin - 1);
  }
};

$.fn.chgTitleColorBlue = function(){$(".td15").removeClass("td15").addClass("td3");};
$.fn.chgTitleColorGray = function(){$(".td3").removeClass("td3").addClass("td15");};


// show the total bar
$.fn.showPgTotalAmount = function(oArr){
  var oTemp = "";
  var sTnD = new Date();
  var sTn = Math.round(sTnD.getTime() / 1000);
  for(x in oArr){
    oTemp = $('span#spanPageAmount' + oArr[x].idx ); 
    oTemp.text(oArr[x].amu);
    if( (oArr[x].tn > 0) && ((sTn - oArr[x].tn) < 30) ){
      oTemp.css({"background-color":"#FFFF99"});
    }else{
      oTemp.css({"background-color":""});
    }
  }
};  
// show the n/m url link
$.fn.setSpanAUrl = function(){
  var myid = $(this).attr("id").substr(4);
  var betdataArr = myid.split("_");
  var dates = $("input:hidden#dates").val();
  var datee = $("input:hidden#datee").val();
  var gametype = $("input:hidden#gametype").val();
  var lid = $("input:hidden#lotto_id").val();
  var xyid = $("#xyid").val();
  var showUrl = '?op=agent&fp=betlist_3d&noback=1&bettype='+betdataArr[0]+'&subid=' + betdataArr[1] + '&num='+ betdataArr[2]+"&dates="+dates+"&datee="+datee+"&gametype="+gametype+"&lid="+lid+"&xyid="+xyid;  
  //window.open(showUrl,'_self','scrollbars=yes');
  var oObj = document.getElementById("divRateRecord");
  oObj.innerHTML = "<div class='bgClc_" + gametype + "' align=right><input type='button' value='&nbsp;X&nbsp;' onclick='javascript:closeDiv();' class='c4'></div><iframe src='" + showUrl + "' width='100%' height='100%'></iframe><br />"; 
  oObj.className = "showRateRecord";
};

// do unow bettype_subid
$.fn.addBnowData = function(){
  var playtype = $("form#frmMenu input#playtypestr").val();
  $("form#frmMyBnow input#palygroup").val(playtype);
  var gametype = $("form#frmMenu input#gametype").val();
  var btnAmount = $("form#frmCheckUnow input#BtnAmount").val();
  if($("div#myDivTbl input:checkbox:checked").size() < 1){
    alert('请勾选号码');
    return false;
  }
  if(btnAmount == ""){btnAmount = 0;}
  $().setCookie(playtype+"BtnAmount3DCK",btnAmount);
  var cn = 0;
  var chkVal = 0;
  var r1passFlag = false;
  var appendStr = "";
  var xyid = 0;
  var xyidNameArr = ['','X盘','Y盘'];
  var myrate = 0;   
  if(playtype != 'rc'){
    xyid = $("#xyid").val();
    $("div#myDivTbl input:checkbox:checked").each(function(idx, ele){
      var titleStr = $(this).attr('name');
      titleStr = titleStr.substr(4, (titleStr.length - 6));
      var mynum = $(this).val();
      var myAmountArr = $("span#url_" + titleStr + "_" + mynum).text().split("/");
      if(myAmountArr.length > 1){
        var myAmount = myAmountArr[1];
        var myrate = $(this).closest("td").children("span.myRate").text();
      }else{
        var myAmount = myAmountArr[0];
        var myrate = $(this).closest("td").prev("td.rate_th2").text();
      }
      var mybtnAmount = Math.min(btnAmount, myAmount);             
      appendStr += "<tr class=td2>";
      appendStr += "<td>" + xyidNameArr[xyid] + "["+ uTitle[titleStr] +"]&nbsp;<b>" + $(this).getBetNumName(titleStr) + "</b></td>";
      appendStr += "<td class=rate_th2>" + myrate + "</td>";
      appendStr += "<td align=right>" + myAmount + "</td>";
      appendStr += "<td align=right><input type=text value=\""+mybtnAmount+"\" name=\"udata"+titleStr+"_"+mynum+"\" size=8 maxlength=8 /></td>";
      appendStr += "</tr>";
      cn++;  
    });
    appendStr += "<tr class=td2><td colspan=4><input type=hidden value=\""+xyid+"\" name=\"xyid\" /></td></tr>";

  }else{
    var numArr = new Array();
    var numOKArr = new Array(); 
    var rateArr = new Array();
    var subNum = $("form#frmMenu input#bid").val();
    var mustNum = 22;
    var numNArr = new Array();
    var monArr = new Array();
    switch(subNum){
      case '9': mustNum = 1; break;
      case '10': mustNum = 2; break;
      case '11': mustNum = 3; break;
      case '12': mustNum = 3; break;               
      case '13': mustNum = 4; break;
      case '14': mustNum = 5; break;
      default: alert('错误的玩法'); return false; break;
    }
    $("div#myDivTbl input:checkbox:checked").each(function(idx, ele){
      numNArr = $(ele).val().split(","); 
      if(numNArr.length == mustNum){
        numArr.push($(ele).val());
        numOKArr.push(numNArr);
        var myrate = 999999;
        for(var n = 0; n < numNArr.length; n++){
          myrate = Math.min(myrate, ($('#myRate_' + numNArr[n]).text() - 0));
        }
        rateArr.push(myrate);
        monArr.push(parseInt($(this).prev("span.span3da").text().split("/")[1]));
      }
      return true;       
    });
    
    if(numArr.length < 1){ alert('勾选个数错误, 无法走飞!'); return false;}
    else{ 
      //numArr.sort(sortNumber);
      var titleStr = subNum + '_0';
      //r1passFlag = true;
      for(var j = 0; j < numArr.length; j++){
        $('#specUnow' + titleStr).val(numArr[j]);
        appendStr += "<tr class=td2>";
        appendStr += "<td>[" + uTitle[titleStr] + "]&nbsp;<b>" + $("#specUnow" + titleStr).getBetNumName(titleStr) + "</b></td>";
        appendStr += "<td class=rate_th2>" +rateArr[j] + "</td>";
        appendStr += "<td align=right>" + monArr[j] + "</td>";
        appendStr += "<td align=right><input type=text value=\"" + Math.min(btnAmount,monArr[j]) + "\" name=\"udata"+titleStr+"_"+ numOKArr[j].join('|') +"\" size=8 maxlength=8 /></td>";
        appendStr += "</tr>";
      }
    }
  }
  if(cn > 0){ $("#btnDoUnow").attr("disabled", "true"); }
  $("#tblMyBnow>tbody").append(appendStr);
  $("#divMyBnow").css("display", "").addClass("showRateRecord");
};


// close the bnow Form
$.fn.closeTheBnowForm = function(){
 $("#tblMyBnow>tbody").empty();
 $("#divMyBnow").css("display", "none").removeClass("showRateRecord");
 $("#btnDoUnow").removeAttr("disabled", "true");
};


// get the bet name of number
$.fn.getBetNumName = function(titleStr){
  // alert(titleStr);
  var titleStrArr = titleStr.split("_");
  if(titleStrArr.length != 2){ return '- error -'; }
  var bettype = titleStrArr[0];
  var subid = titleStrArr[1];
  var num = $(this).val();
          
  switch(bettype){
     case '0':
        return num;
        break;
     case '2':
        var tempArr = [ '', '单','双'];
        return tempArr[num];
        break;
     case '1':
        var tempArr = [ '', '大','小'];
        return tempArr[parseInt(num)];
        break;
     case '3':
        var tempArr = [ '', '11','22','33','44','55','66'];
        return tempArr[parseInt(num)];
        break;
     case '4':
        var tempArr =  [ '', '111','222','333','444','555','666'];
        return tempArr[parseInt(num)];
        break;
     case '5':
        return '全骰';
        break;
     case '6':
        var tempArr = [ '','12','13','14','15','16','23','24','25','26','34','35','36','45','46','56'];
        return tempArr[parseInt(num)];
        break;
     case '7':
        var tempArr = ['', '4','5','6','7','8','9','10','11','12','13','14','15','16','17'];
        return tempArr[parseInt(num)];
        break;
     case '8':
        var tempArr = ['', '对子','散号'];
        return tempArr[parseInt(num)];
        break;
      return num;
      break;
   }
   return '-null-';
};


function sortNumber(a, b){ return a - b; }
// -----------------------------------------------------------------------------
// print table functions
// -----------------------------------------------------------------------------
// 双面盘
function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  var winlostStr = "";
  var setSpanAUrl = "";
  var setBtnId = "";
  var idx = 0;          // 阵列index
  var tempI = 0;        // 1, 2 (大, 小)    
  var str = "";
  var strTitle = "";
  var oObj = "";
  var num = 0;
  var setBtnId = "";
  var nextI = -1;        // 可秀玩法
  var i = 0;
  var l = 0;
  var l2 = 0;
  var littletotal = 0;
  var classCount = 0;
  var titleTemp = '';
  var colTemp = '';
  var tempCount = 0;
  for(i = 0, l = rdata.length; i < l; i++ ){
    l2 = showTitleArr[i].length;
    for(var j = 0; j < l2; j++){  // 双面
      tempCount++;
      oObj = rdata[i][j];
      num = oObj.numbers;
      winlostStr = ( oObj.winlost < 0 ) ? "#FF00FF" : "green" ;                                         // 输赢的颜色
      setSpanAUrl = "class=span3da id='url_" +  bettype[i] + "_" + subBettype[i] + "_" + oObj.numbers + "'"; // 笔数与金额的连结
      setBtnId = "b_"+  bettype[i] + "_" + subBettype[i] + "_" + oObj.numbers;
      
      str += "<th class=td6>" + showTitleArr[i][j] + "</th>";
      str += "<td id='td_r" + bettype[i] +  "_" + subBettype[i] + "_" + num + "' class='" + oObj.bgclass + "'>";
      str += "<span class='myRate'>" + oObj.rate + "</span><br />";
      str += "<span " + setSpanAUrl + " >" + oObj.totalnum + "/" + oObj.amount + "</span>";
      str += "<br /><input type='checkbox' name='unow"+ bettype[i] + "_" + subBettype[i]+"[]' value='"+oObj.numbers+"' />";
      str += "</td>";  
      str += "<td align=right><font color=" + winlostStr + ">" + oObj.winlost + "</font></td>";
      if(oObj.bgclass != "") classCount = "namount";
    }
  }
  if(tempCount < tdNum){
   for(i = 0; i < (tdNum - tempCount); i++){
    str += '<td></td><td></td><td></td>';
   }
  }
  // count little total
  for(i = 0, l = rtotaldata.length; i < l; i++){
    littletotal += rtotaldata[i].amount - 0;
  }
  
  strTitle += "<tr class='td2 bigBottom' align=center>";
  if(rowSpanN > 1){ strTitle += "<th class=td6 rowspan=" + rowSpanN + ">" + sTitle + "</th>"; }
  else if(rowSpanN == 1){ strTitle += "<th class=td6>" + sTitle + "</th>"; }
  strTitle += "<th class='span3dall " + classCount + "'>" + littletotal + "</th>";
  
  return strTitle + str;

}

// 定位,连码
function crt_1To21(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, iNumTr,ItemTitle){
  var str = "";
  var winlostStr = "";
  var setSpanAUrl = "";
  var setBtnId = "";
  var htmlTemp = '<tr class="td2">';
  var htmlTitle = '<th>项目</th><th>注单</th><th>输赢</th>';
  var trArr = new Array();
  var idx = 0;
  var dataLen = rdata.length;
  var i = 0;                
  for(i = 0; i < iNumTr; i++){ trArr[i] = '';} 
  var oObj = 0;              
  var showTitleN = Math.floor(dataLen / iNumTr);
  if((dataLen % iNumTr) > 0){showTitleN += 1; }           
  str += '<caption class="td0 bgClc_' + myGlobalVal.gametype  + '">' + sTitle + '</caption>';
  str += '<thead><tr class="td15">';
  for(i = 0; i < showTitleN; i++){
    str += htmlTitle;
  }
  str += '</tr></thead>';
  str += '<tbody align=center>';
  for(i = 0; i < dataLen; i++){
    idx = i % iNumTr;
    oObj = rdata[i];
    winlostStr = ( oObj.winlost < 0 ) ? "#FF00FF" : "green";
    setSpanAUrl = " class=span3da id='url_" +  bettype + "_" + subBettype + "_" + oObj.numbers + "'"; // 笔数与金额的连结
    setBtnId = "b_"+  bettype + "_" + subBettype + "_" + oObj.numbers;
    trArr[idx] += "<th class=td6>" + ItemTitle[oObj.numbers] + "</th>";
    trArr[idx] += "<td class='" + oObj.bgclass + "'><span class='myRate'>"+ oObj.rate + "</span><br /><span " + setSpanAUrl + ">" + oObj.totalnum + "/" + oObj.amount + "</span>";
    trArr[idx] += "<br /><input type='checkbox' name='unow"+ bettype + "_" + subBettype + "[]' value='"+oObj.numbers + "' />";
    trArr[idx] += "</td>"; 
    trArr[idx] += "<td nowrap class='jsbo' align=right><font color=" + winlostStr + ">" + oObj.winlost + "</font></td>";
  }
  if(idx++ != iNumTr){
    for(i = idx; i < iNumTr; i++){
      trArr[i] += '<td></td><td></td><td></td>';
    }
  }
  str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr>'; 
  return str;
}

// 连码
function crt_1To21_nochk(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, iNumTr){
  var str = "";
  var winlostStr = "";
  var setSpanAUrl = "";
  var setBtnId = "";
  var htmlTemp = '<tr class="td2">';
  var htmlTitle = '<th>项目</th><th>注单</th><th>输赢</th>';
  var trArr = new Array();
  var idx = 0;
  var dataLen = rdata.length;
  var i = 0;                
  for(i = 0; i < iNumTr; i++){ trArr[i] = '';} 
  var oObj = 0;              
  var showTitleN = Math.floor(dataLen / iNumTr);
  if((dataLen % iNumTr) > 0){showTitleN += 1; }           
  str += '<caption class="td0 bgClc_' + myGlobalVal.gametype  + '">' + sTitle + '</caption>';
  str += '<thead><tr class="td15">';
  for(i = 0; i < showTitleN; i++){
    str += htmlTitle;
  }
  str += '</tr></thead>';
  str += '<tbody align=center>';
  for(i = 0; i < dataLen; i++){
    idx = i % iNumTr;
    oObj = rdata[i];
    winlostStr = ( oObj.winlost < 0 ) ? "#FF00FF" : "green";
    setSpanAUrl = " class=span3da id='url_" +  bettype + "_" + subBettype + "_" + oObj.numbers + "'"; // 笔数与金额的连结
    setBtnId = "b_"+  bettype + "_" + subBettype + "_" + oObj.numbers;
    trArr[idx] += "<th class=td6>" + oObj.numbers + "</th>";
    trArr[idx] += "<td class='" + oObj.bgclass + "'><span class='myRate' id='myRate_" + oObj.numbers + "'>"+ oObj.rate + "</span><br /><span " + setSpanAUrl + ">" + oObj.totalnum + "/" + oObj.amount + "</span>";
    // trArr[idx] += "<br /><input type='checkbox' name='unow"+ bettype + "_" + subBettype + "[]' value='"+oObj.numbers + "' />";
    trArr[idx] += "</td>"; 
    trArr[idx] += "<td nowrap class='jsbo' align=right><font color=" + winlostStr + ">" + oObj.winlost + "</font></td>";
  }
  if(idx++ != iNumTr){
    for(i = idx; i < iNumTr; i++){
      trArr[i] += '<td></td><td></td><td></td>';
    }
  }
  str += htmlTemp + trArr.join('</tr><tr class=td2>') + '</tr>'; 
  return str;
}

// 热门100
function crt_rcNumGroup(bettype, rcObj, rcTitle){
  var rcTdArr = [[],[],[],[]];
  var rcTdIdx = 0;
  var strTbl = "";
  var rcNumGroupL = rcObj.length;
  var strNumStr = "";
  strTbl += "<table class='tblMy3D' width='100%' >";
  strTbl += "<caption class='bgImg_" + myGlobalVal.gametype + "'>" + rcTitle + " - 热门100号</caption>";
  for(i = 0; i < rcNumGroupL; i++){
    rcTdIdx = parseInt(i / 25);
    strNumStr = rcObj[i].num + "<span style='padding-left:10px;padding-right:10px;width:100px;' class=span3da id='url_" +  bettype + "_0_" + rcObj[i].num + "' >" + rcObj[i].tn + "/" + rcObj[i].amu + "</span>";
    if(rcObj[i].amu > 0){
      strNumStr += "<input type='checkbox' name='unow"+ bettype + "_0[]' value='" + rcObj[i].num + "' />";
    }else{
      strNumStr += "<input type='checkbox' disabled />";
    }
    rcTdArr[rcTdIdx].push( "<div class='" + rcObj[i].bgclass + "'>" + strNumStr + "</div>");
  }
  strTbl += "<tr>";
  for(i = 0; i < rcTdArr.length; i++){
    if(rcTdArr[i].length > 0){
      strTbl += "<td valign='top'>" + rcTdArr[i].join("") + "</td>";
    }
  }
  strTbl += "</tr>";
  strTbl += "</table>";
  return strTbl;
}

// 切换 subbid
function chgsubid(subid){
  var subidStr = subid.toString();
  $('form#frmMenu input#subid').val(subid);
  $("input#btnReflash").click();
}

// 切换 bid
function chgbid(bid){
  var bidStr = bid.toString();
  $('form#frmMenu input#bid').val(bid);
  $("input#btnReflash").click();
}

// -----------------------------------------------------------------------------
// 玩法呼叫的function 
// -----------------------------------------------------------------------------
  
// 主盘势    
function show_r1(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px">',
  '02':'<img src="skin/1/img/ball/2.png" width="20px">',
  '03':'<img src="skin/1/img/ball/3.png" width="20px">',
  '04':'<img src="skin/1/img/ball/4.png" width="20px">',
  '05':'<img src="skin/1/img/ball/5.png" width="20px">',
  '06':'<img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/7.jpg" width="20px">',
  '02':'<img src="skin/1/img/ball/8.jpg" width="20px">'};
  strTbl += crt_1To21(ratedata.r0_0, ratedata.r0_0total, "", 0, 0, '三军',3,showBetSubArr);
  strTbl += crt_1To21(ratedata.r1_0, ratedata.r1_0total, "", 1, 0, '',1,showBetSubArr2);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}
function show_r2(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/1.png" width="20px">',
  '02':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px">',
  '03':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '04':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '05':'<img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '06':'<img src="skin/1/img/ball/6.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/9.jpg" width="40px">',
  '02':'<img src="skin/1/img/ball/10.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r3_0, ratedata.r3_0total, "", 3, 0, '短牌',3,showBetSubArr);
  strTbl += crt_1To21(ratedata.r8_0, ratedata.r8_0total, "", 8, 0, '',1,showBetSubArr2);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}

function show_r3(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/1.png" width="20px">',
  '02':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px">',
  '03':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '04':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '05':'<img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '06':'<img src="skin/1/img/ball/6.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">'};
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/11.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r4_0, ratedata.r4_0total, "", 4, 0, '豹子/全骰',3,showBetSubArr);
  strTbl += crt_1To21(ratedata.r5_0, ratedata.r5_0total, "", 5, 0, '',1,showBetSubArr2);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}
function show_r4(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/2.png" width="20px">',
  '02':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '03':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '04':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '05':'<img src="skin/1/img/ball/1.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '06':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/3.png" width="20px">',
  '07':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '08':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '09':'<img src="skin/1/img/ball/2.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '10':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/4.png" width="20px">',
  '11':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '12':'<img src="skin/1/img/ball/3.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '13':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/5.png" width="20px">',
  '14':'<img src="skin/1/img/ball/4.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">',
  '15':'<img src="skin/1/img/ball/5.png" width="20px"><img src="skin/1/img/ball/6.png" width="20px">'
  };
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/9.jpg" width="40px">',
  '02':'<img src="skin/1/img/ball/10.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r6_0, ratedata.r6_0total, "", 6, 0, '短牌',3,showBetSubArr);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}
function show_r5(_lotto_id, playtype, ratedata, myHeader){
  var strTbl = "<table class='tblMy3D' width='990' >";
  //strTbl += _myHeader;
  var showBetSubArr = {'01':'<img src="skin/1/img/ball/a4.png" width="40px">',
  '02':'<img src="skin/1/img/ball/a5.png" width="40px">',
  '03':'<img src="skin/1/img/ball/a6.png" width="40px">',
  '04':'<img src="skin/1/img/ball/a7.png" width="40px">',
  '05':'<img src="skin/1/img/ball/a8.png" width="40px">',
  '06':'<img src="skin/1/img/ball/a9.png" width="40px">',
  '07':'<img src="skin/1/img/ball/a10.png" width="40px">',
  '08':'<img src="skin/1/img/ball/a11.png" width="40px">',
  '09':'<img src="skin/1/img/ball/a12.png" width="40px">',
  '10':'<img src="skin/1/img/ball/a13.png" width="40px">',
  '11':'<img src="skin/1/img/ball/a14.png" width="40px">',
  '12':'<img src="skin/1/img/ball/a15.png" width="40px">',
  '13':'<img src="skin/1/img/ball/a16.png" width="40px">',
  '14':'<img src="skin/1/img/ball/a17.png" width="40px">'
  };
   var showBetSubArr2 = {'01':'<img src="skin/1/img/ball/9.jpg" width="40px">',
  '02':'<img src="skin/1/img/ball/10.jpg" width="40px">'};
  strTbl += crt_1To21(ratedata.r7_0, ratedata.r7_0total, "", 7, 0, '总点数',3,showBetSubArr);
  strTbl += "</table>";
  
  //function crt_2face_com(rdata, rtotaldata, rnum, bettype, subBettype, sTitle, showTitleArr, rowSpanN, tdNum){
  $("#myDivTbl").html(strTbl);
}

function show_default(){
  $("#myDivTbl").html('页面建构中....');
}


// 全部      
function show_all(_lotto_id, playtype, ratedata){
  _playtype = playtype;
  var strTbl = "";
  $("#myDivTbl").html(strTbl);
}


// -----------------------------------------------------------------------------
// 按了玩法执行结果
// -----------------------------------------------------------------------------
function clickTitle(playtype){
  if(playtype == 'r1all'){
    showOnlinebetAll(myGlobalVal.gametype, myGlobalVal.lotto_id);
    return;  
  }
 $("#myDivNow").empty();
 $("#myDivTblTop").empty();
 $("#myDivTbl").html('<span class="bgClc_' + myGlobalVal.gametype + '" style="padding:10px; border:1px #926F4A dashed;">Loading.....(资料下载中...请稍后...)<img src="image/loading.gif" /></span>');
 _playtype = playtype;
 
 $("form#frmMenu input#playtypestr").val(playtype);
 $("form#frmMenu input#bid").val("");
 $("form#frmMenu #xyid").css("display", "");
 $("#noxystr").addClass("noneRateRecord");
 // -- $("form#frmMenu input#subid").val("0");
 switch(playtype){
  case 'rnp':
    var subidTemp = $("form#frmMenu input#subid").val();
    $("form#frmMenu #xyid").css("display", "none");
    $("#noxystr").toggleClass("noneRateRecord");
    var chkStr = ",1,2,3,4,5,";
    if(chkStr.indexOf("," + subidTemp + ",") < 0){ subidTemp = "1"; }
    $("form#frmMenu input#subid").val(subidTemp);
    break;
  case 'rc': 
    var bidTemp = $("#bid5h").val();
    var chkStr = ",9,10,11,12,13,14,";
    $("form#frmMenu input#subid").val('0');
    if(chkStr.indexOf("," + bidTemp + ",") < 0){ bidTemp = "9"; }
    $("form#frmMenu input#bid").val(bidTemp);
    $("form#frmMenu #xyid").css("display", "none");
    $("#noxystr").toggleClass("noneRateRecord");
    $("#myDivTblTop").html('<input type="hidden" name="unow' + bidTemp + '_0[]" value="" id="specUnow' + bidTemp + '_0" />');
    break;
 }
 
 $("th.cbig").removeClass('cbig');
 $("th#myThBar" + playtype).addClass('cbig');
 
 // 切换快选画面
 //var str = "<table width='990' class='table0' cellPadding=5></table>";
 //switch(playtype){
 //   default : $("#myDivNow").html('预留区块'); break;
 //}
 
 var btnAmount5HCK = $().getCookie(playtype+'BtnAmount5HCK','');
 $("form#frmCheckUnow input#BtnAmount").val([btnAmount5HCK]);
 
 $("input#btnReflash").click();
}

// -----------------------------------------------------------------------------
// for now page
// -----------------------------------------------------------------------------

$(function(){
  
  nowdate();
  countdown();
  
  // button of reload, just reflash rates instade of reload all page
  $("input#btnReflash").click(function(){
    $("span#reflashtimeMin").text(myGlobalVal.reloadCK);
    $(this).getAjaxDataAuto(_playtype, __roundID);
    $("form#frmMenu input").add("form#frmMenu select").attr("disabled","true");
  });
  // reflash data by change xy id
  $("form#frmMenu select").change(function(){
    $("input#btnReflash").click();
  });
    
  // my data of fly
  $("input#btnShowBet2").click(function(){
     var showUrl = "?op=agent&fp=bet2list_3d&showType=0&dates=" + myGlobalVal.open + "&datee=" + myGlobalVal.open + "&num=all&gametype=" + myGlobalVal.gametype + "&lid=" + myGlobalVal.lotto_id_3d;
     window.open(showUrl,'_blank','scrollbars=yes,width=960,height=600');
  });
  
  // 走飞 -- 二面
  $("form#frmCheckUnow input:button#btnDoUnow").bind('click',function(){
    $().addBnowData();
  });
  
  // button of fly detail
  $("input#btnBnowReadMe").click(function(){
    var X = (screen.width-560)/2;
	  var Y = (screen.Height-240)/2;
    window.open('?op=agent&fp=bnowreadme_3d','WinPopList','menubar=no,status=yes,scrollbars=no,toolbar=no,top='+Y+',left='+X+',width=560,height=240');
  });
  
  // close do bnow form
  $("#btnCloseTheBnowForm2").click(function(){ $().closeTheBnowForm(); });
  
  clickTitle(myGlobalVal.playtypestr);
  
});